package com.atguigu.gmall2023sugar.service;

import com.atguigu.gmall2023sugar.bean.Traffic;
import com.atguigu.gmall2023sugar.mapper.TrafficMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author lzc
 * @Date 2023/7/18 14:30
 */
@Service
public class TrafficServiceImpl implements TrafficService {
    
    @Autowired
    TrafficMapper trafficMapper;
    
    @Override
    public List<Traffic> traffic(String date) {
        return trafficMapper.traffic(date);
    }
    
    @Override
    public Map<String, Long> kw(String date) {
        List<Map<String, Object>> list = trafficMapper.kw(date);
        
        Map<String, Long> result = new HashMap<>();
        // list有多少行,则表示 result 就有多少个 key
        
        for (Map<String, Object> map : list) {
            String key = map.get("keyword").toString();
            Long v = (Long) map.get("keyword_count");
            
            result.put(key, v);
        }
        
        return result;
    }
    
}
